﻿using AvaMaid.Messages;
using CommunityToolkit.Mvvm.Messaging;
using FanaticGene.AvaloniaMaid.Core.Analyzer;
using System.Linq;
using System.Windows;

namespace AvaMaid
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window, IRecipient<IPCParamsEventArgs>
    {
        public MainWindow()
        {
            WeakReferenceMessenger.Default.Register(this);
            InitializeComponent();
        }

        void IRecipient<IPCParamsEventArgs>.Receive(IPCParamsEventArgs message)
        {
            var analyzer = new CodeAnalyzer();
            var args = message.Args;

            var domain = analyzer.GetClassDomain(args.ElementAtOrDefault(0), args.ElementAtOrDefault(1), args.ElementAtOrDefault(2));
            if (domain != null)
            {
                var classDomainArgs = new ClassDomainLoadedEventArgs() { ClassDomain = domain };
                WeakReferenceMessenger.Default.Send(classDomainArgs);
            }

        }
    }
}
